home *** CD-ROM | disk | FTP | other *** search
- package com.glenpike.loader
- {
- import flash.events.ErrorEvent;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.HTTPStatusEvent;
- import flash.events.IOErrorEvent;
- import flash.events.SecurityErrorEvent;
- import flash.net.URLLoader;
- import flash.net.URLLoaderDataFormat;
- import flash.net.URLRequest;
-
- public class TextLoader extends EventDispatcher
- {
- private var _text:String;
-
- private var _ldr:URLLoader;
-
- public function TextLoader()
- {
- super();
- _init();
- }
-
- public function loadFile(param1:String) : void
- {
- var _loc2_:URLRequest = null;
- _text = null;
- _loc2_ = new URLRequest(param1);
- _ldr.load(_loc2_);
- }
-
- private function onIOError(param1:IOErrorEvent) : void
- {
- trace("IOError " + param1.text);
- dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,"Failed to load file"));
- }
-
- private function onSecurityError(param1:SecurityErrorEvent) : void
- {
- trace("SecurityError " + param1.text);
- dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,"Not allowed to laod file"));
- }
-
- private function onHTTPStatusEvent(param1:HTTPStatusEvent) : void
- {
- trace("HTTPStatus " + param1.status);
- }
-
- public function get text() : String
- {
- return _text;
- }
-
- private function onDataLoad(param1:Event) : void
- {
- _text = param1.target.data;
- trace("loaded " + text.substr(0,20));
- dispatchEvent(new Event(Event.COMPLETE));
- }
-
- private function _init() : void
- {
- _ldr = new URLLoader();
- _ldr.dataFormat = URLLoaderDataFormat.TEXT;
- _ldr.addEventListener(Event.COMPLETE,onDataLoad,false,0,true);
- _ldr.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);
- }
- }
- }
-
-